﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeatherStationSys.Interface;

namespace WeatherMonitoringSystem
{
    public class TemperatureSensor : ISubject
    {
        private List<IObserver> _container;
        private AbstractTemperatureSensor _abstractTemperatureSensor;
        private AlarmClock _alarmClock;

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="ac"></param>
        /// <param name="st"></param>
        public TemperatureSensor(AlarmClock ac, StationTookit st)
        {
            _container = new List<IObserver>();
            _abstractTemperatureSensor = st.MakeTemperature();
            _alarmClock = ac;

            _alarmClock.Tic();
        }

        public void AddObserver(IObserver obj)
        {
            _container.Add(obj);
        }

        public void Check()
        {
            _abstractTemperatureSensor.Check();
        }

        public void NotifyObservers(double temp)
        {
            foreach (var item in _container)
            {
                ((IObserver)item).Update(temp);
            }
        }

        public void UnRegisterObserver(IObserver obj)
        {
            _container.Remove(obj);
        }
    }
}
